using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class OpenBoxUI : MonoBehaviour
{
	private GameObject uiobj;

	public GameObject camobj;

	public GameObject boxobj;

	public GameObject lightobj;

	public GameObject lightbobj;

	public GameObject kuangobj;

	public UIWidget GetRewardwi;

	public UIEventListener backbgbtn;

	public UISprite backflag;

	public Animation openanima;

	private bool animaflag;

	public List<int> showitemlist = new List<int>();

	public UIWidget[] itemwi;

	public TweenScale[] animaitemscales;

	public TweenPosition[] animaitempos;

	private float timecal;

	private float intertimevalue = 0.3f;

	private int curindex;

	private Vector3 fromscale = new Vector3(3f, 3f, 3f);

	private Vector3 toscale = new Vector3(1f, 1f, 1f);

	private Vector3 frompos = new Vector3(0f, -60f, 0f);

	private void Start()
	{
		backbgbtn.onClick = backbgfun;
	}

	private void Update()
	{
		if (!animaflag)
		{
			return;
		}
		timecal += Time.deltaTime;
		if (timecal > intertimevalue)
		{
			timecal = 0f;
			if (curindex < showitemlist.Count)
			{
				animaitemscales[showitemlist[curindex]].from = fromscale;
				animaitemscales[showitemlist[curindex]].to = toscale;
				animaitempos[showitemlist[curindex]].from = frompos;
				animaitemscales[showitemlist[curindex]].duration = intertimevalue;
				animaitempos[showitemlist[curindex]].duration = intertimevalue;
				animaitemscales[showitemlist[curindex]].ResetToBeginning();
				animaitempos[showitemlist[curindex]].ResetToBeginning();
				animaitemscales[showitemlist[curindex]].PlayForward();
				animaitempos[showitemlist[curindex]].PlayForward();
				itemwi[showitemlist[curindex]].alpha = 1f;
				itemwi[showitemlist[curindex]].gameObject.SetActive(true);
				curindex++;
			}
			else if (curindex > showitemlist.Count)
			{
				animaflag = false;
				backflag.alpha = 1f;
				backflag.gameObject.SetActive(true);
				curindex = 0;
			}
			else
			{
				curindex++;
			}
		}
	}

	public void clearlist()
	{
		showitemlist.Clear();
	}

	public void Additem(int itemnum)
	{
		showitemlist.Add(itemnum);
	}

	public void SetFalseObj()
	{
		if (uiobj == null)
		{
			uiobj = base.gameObject;
		}
		NGUITools.SetActive(uiobj, state: false);
	}

	public void init_ui_info()
	{
		MenuBackController.instance.ChangeMenuUIstate(MenuUIState.openboxui);
		UnityVersionUtil.SetActiveRecursive(camobj, state: true);
		UnityVersionUtil.SetActiveRecursive(boxobj, state: true);
		UnityVersionUtil.SetActiveRecursive(kuangobj, state: true);
		UnityVersionUtil.SetActiveRecursive(lightobj, state: false);
		UnityVersionUtil.SetActiveRecursive(lightbobj, state: false);
		backflag.alpha = 0f;
		backflag.gameObject.SetActive(false);
		openanima.Play("openbox");
		StartCoroutine("timercal");
	}

	private IEnumerator timercal()
	{
		for (float k = 0f; k < 0.2f; k += Time.deltaTime)
		{
			yield return 0;
		}
		UnityVersionUtil.SetActiveRecursive(lightobj, state: true);
		MonoInstance<AudioController>.instance.play(AudioType.openbox, 0f);
		for (float j = 0f; j < 0.9f; j += Time.deltaTime)
		{
			yield return 0;
		}
		UnityVersionUtil.SetActiveRecursive(lightbobj, state: true);
		for (float i = 0f; i < 0.15f; i += Time.deltaTime)
		{
			yield return 0;
		}
		UnityVersionUtil.SetActiveRecursive(camobj, state: false);
		UnityVersionUtil.SetActiveRecursive(boxobj, state: false);
		UnityVersionUtil.SetActiveRecursive(kuangobj, state: false);
		GetRewardwi.alpha = 1f;
		GetRewardwi.gameObject.SetActive(true);
		animaflag = true;
		curindex = 0;
		timecal = 0f;
	}

	public void backbgfun(GameObject btn)
	{
		if (UnityVersionUtil.IsActive(uiobj))
		{
			disable();
		}
	}

	public void enable()
	{
		if (uiobj == null)
		{
			uiobj = base.gameObject;
		}
		NGUITools.SetActive(uiobj, state: true);
		init_ui_info();
	}

	public void disable()
	{
		animaflag = false;
		GetRewardwi.alpha = 0f;
		GetRewardwi.gameObject.SetActive(false);
		NGUITools.SetActive(uiobj, state: false);
		MenuBackController.instance.BackMenuUIstate();
	}
}
